function M = sllabelmap(a, b, op)
%SLLABELMAP Constructs logical matrix representing label matches
%
% [ Syntax ]
%   - M = sllabelmap(a, b)
%   - M = sllabelmap(a, b, 'sparse')
%
% [ Description ]
%   - M = sllabelmap(a, b) constructs logical matrix that reflects the
%     matching of labels between a and b.
%
%     a and b should be both vectors. Let m, n be the lengths of a and b.
%     then M will be an m x n matrix defined as follows
%       M(i, j) = (a(i) == b(j))
%
%   - M = sllabelmap(a, b) constructs the label map M as a sparse logical
%     matrix.
%
% [ History ]
%   - Created by Dahua Lin, on Jan 4, 2008
%

%% parse and verify input arguments

assert(isnumeric(a) && isvector(a) && isnumeric(b) && isvector(b), ...
    'sltoolbox:sllabelmap:invalidarg', ...
    'a and b should be both numeric vectors.');

if nargin >= 3
    assert(ischar(op) && strcmp(op, 'sparse'), ...
        'sltoolbox:sllabelmap:invalidarg', ...
        'The 3rd argument for sllabelmap is invalid.');
    
    make_sparse = true;
    
else
    make_sparse = false;
end


%% main

if size(a, 2) > 1
    a = a';
end
if size(b, 1) > 1
    b = b';
end
M = bsxfun(@eq, a, b);

if make_sparse
    M = sparse(M);
end
